﻿using System;
using System.Web.UI.WebControls;
using Medianamik.Core;
using Medianamik.Core.Redirect;

namespace Medianamik.UI.RedirectManagement
{
    public partial class RedirectManagement : BaseModuleEditionPage<RedirectNode>
    {

        protected bool IsNew
        {
            get
            {
                return Request.QueryString[NodeIdParamName] == null;
            }
        }
        
        protected override string ReturnURL
        {
            get { return "Default.aspx"; }
        }

        public override Controls.MedianamikFormTemplate MedianamikFormTemplate
        {
            get { return Fields; }
        }

        public override Guid? TypeId
        {
            get
            {
                return new RedirectNode().SystemNodeTypeID;
            }
        }

        protected override string NodeIdParamName
        {
            get
            {
                return "id";
            }
        }

        protected override void Save(object sender, EventArgs e)
        {
            string message = IsNew ? "Redirect Created" : "Redirect Modified";
            var node = MedianamikFormTemplate.GetFormValue(CurrentNode);
            if (node != null)

            {
                var logger = new Core.Logging.ActivityLogger();
                logger.Log(new Core.Logging.LoggableObject(node.RedirectFrom, Core.Logging.LogEntryType.Redirect), message);
            }
            base.Save(sender, e);
        }

        public override LinkButton SaveButton
        {
            get { return btnSave; }
        }

        protected override Guid? ParentNodeId
        {
            get
            {
                return MedianamikModules.RedirectManagement;
            }
        }
    }
}
